package com.dragon.repository.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.dragon.repository.entity.SchedulingSon;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author sy
 * @since 2023-12-06
 */
@Mapper
public interface SchedulingSonMapper extends BaseMapper<SchedulingSon> {

    @Select("<script>" +
            "SELECT dss.*, dvp.`name` AS productName, dp.name AS produceName , dpp.num as contractNum, " +
            "dvp.material as VproductMaterial, dvp.remark as VproductRemark FROM dragon_scheduling_son dss " +
            "LEFT JOIN dragon_vendor_products dvp on dss.product_id = dvp.id " +
            "LEFT JOIN dragon_produce dp on dss.produce_id = dp.id " +
            "LEFT JOIN dragon_produce_products dpp on dpp.produce_id = dss.produce_id and dpp.quotes_product_id = dss.product_id " +
            "WHERE dss.scheduling_id = #{schedulingId} and dss.type = 1  " +
            "<if test='produceId != null'> "+
            "AND dss.produce_id = #{produceId}" +
            "</if> " +
            "<if test='equipmentId != null and equipmentId != \"\"'> "+
            "AND dss.equipment_id = #{equipmentId}" +
            "</if> " +
            "</script>")
    List<SchedulingSon> getListBySchedulingId(Integer schedulingId, Integer produceId, Integer equipmentId);

}
